Skip to content

Bundle a single copy of Monaco core in playground-v2 - #3710

Open
Jake Bailey (jakebailey) wants to merge 2 commits into
microsoft:v2from
jakebailey:monaco-dedupe
Open

Jake Bailey (jakebailey) wants to merge 2 commits into
microsoft:v2from
jakebailey:monaco-dedupe

Conversation

@jakebailey

Copy link
Copy Markdown
Member

playground-v2 builds its editor from monaco-editor-core 0.56 (patched via patches/monaco-editor-core@0.56.0.patch for touch gestures), while importing the TypeScript/JavaScript Monarch language definitions, the links contribution, and the editor worker entry from monaco-editor 0.56. Because monaco-editor ships its own complete esm/vs tree and resolves relative imports within it, the bundle included a second, unpatched copy of the Monaco core with separate service and registry instances.

This change:

  • Removes the redundant monaco-editor/editor/contrib/links/browser/links.js import, as monaco-editor-core already registers the links contribution through editor.main / editor.all.js.
  • Adds an esbuild plugin that redirects relative imports from monaco-editor into vs/ to the matching modules in monaco-editor-core (built from the same VS Code commit), and fails the build if any monaco-editor module with a monaco-editor-core counterpart remains in the bundle inputs.
Output / Metric Before After Change
main.js 14,277,655 B 8,987,685 B -37.1%
main.css 335,417 B 237,857 B -29.1%
editor.worker.js 607,076 B 619,474 B +2.0% (now shares patched core)
monaco-editor vs/ modules in bundle 701 2 -699 (only TS/JS language definitions remain)

monaco-editor-core's editor.main already registers the links
contribution through editor.all. Importing the contribution from
monaco-editor pulls in that package's separate copy of the editor core,
so the registration lands in an editor instance the playground never
uses while adding hundreds of duplicate modules to the bundle.
The Monarch language definitions and the editor worker entry come from
monaco-editor, which ships its own build of the editor core under
esm/vs. Bundling them as-is includes a second copy of Monaco with its
own service registries, which inflates the playground bundle and misses
the patch applied to monaco-editor-core.

Both packages are built from the same VS Code commit, so the relative
imports from monaco-editor into vs/ can resolve to the equivalent
monaco-editor-core modules. The build also fails if any monaco-editor
module with a monaco-editor-core counterpart ends up in the output, so
a future mismatch between the two packages is caught early.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant